/*
 * Copyright (c) 2017.  . All rights reserved.
 */

package com.fenxiangle.yueding.framework;

import android.app.ActivityManager;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.utils.DynamicTimeFormat;
import com.fenxiangle.yueding.R;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;

import cn.jpush.android.api.JPushInterface;


/**
 *
 * @e-mail
 * @date 2017/3/27 14:15
 */

public class LibManager {


    public void init(Context app) {
        //初始化第三方库
        initJPush(app);
        initUM(app);


        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @NonNull
            @Override
            public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.window_background, R.color.primary_comparison);//全局设置主题颜色
                return new ClassicsHeader(context).setTimeFormat(new DynamicTimeFormat("更新于 %s"));
            }
        });
        SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
            @NonNull
            @Override
            public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
                return new ClassicsFooter(context).setDrawableSize(20);
            }
        });
    }

    /**
     * 友盟
     */
    private static void initUM(Context app) {
        UMConfigure.init(app,"5b939334f43e481d19000716"
                ,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");
        PlatformConfig.setWeixin("wx47e485dbc81c3807", "1a5177a41e55792a8bad88ffa41079d1");
        PlatformConfig.setQQZone("1107815120", "tFRjn92sUMjgKEhf");
        PlatformConfig.setSinaWeibo("1359578604", "12420d53181d88e0f2c975762576e892","http://api.weibo.com/oauth2/default.html");
    }

    /**
     * 极光推送
     */
    private void initJPush(Context app) {
        JPushInterface.setDebugMode(AM.isDebug());    // 设置开启日志,发布时请关闭日志
        JPushInterface.init(app);            // 初始化 JPush
        JPushInterface.stopCrashHandler(app);
    }



    /**
     * 获得当前进程的名字
     *
     * @param context
     * @return
     */
    public static String getCurProcessName(Context context) {

        int pid = android.os.Process.myPid();

        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);

        for (ActivityManager.RunningAppProcessInfo appProcess : activityManager
                .getRunningAppProcesses()) {

            if (appProcess.pid == pid) {

                return appProcess.processName;
            }
        }
        return null;
    }
}
